package com.tangruojie.lambda;

import java.util.function.IntBinaryOperator;

public class LambdaDemo02 {

    public static int calculateNum(IntBinaryOperator operator) {
        int a = 10;
        int b = 20;
        return operator.applyAsInt(a, b);
    }

    public static void main(String[] args) {

        /**
         * 匿名内部类
         */
        int i = calculateNum(new IntBinaryOperator() {
            @Override
            public int applyAsInt(int left, int right) {
                return left + right;
            }
        });
        System.out.println(i);

        /**
         * Lambda表达式
         */
        int j = calculateNum(Integer::sum);
        System.out.println(j);

        /**
         * 函数式接口
         * 外部实现
         * 内部使用
         * 及时即用
         */
        IntBinaryOperator intBinaryOperator = new IntBinaryOperator() {
            @Override
            public int applyAsInt(int left, int right) {
                return left + right;
            }
        };
        int k = calculateNum(intBinaryOperator);
        System.out.println(k);

    }

}
